<title>评价管理</title>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>评价管理</cite></a>
    <a><cite>评价列表</cite></a>
  </div>
</div>

<div class="layui-fluid">

  <div class="layui-card">
    <div class="layui-card-body">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist">
        <div class="layui-form-item">

          <div class="layui-inline">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
              <input type="text" name="nickname" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
        <div style="padding-bottom: 10px;">
        </div>

        <table class="layui-hide" id="table-instance" lay-filter="table-instance"></table>

        <script type="text/html" id="table-useradmin-admin">
         <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-2"></i>回复</a>
         <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-4"></i>删除</a>
     
        </script>
      </div>
    </div>
  </div>
  <style type="text/css">
    .layui-table-cell {
      height: auto;
      line-height: 28px;
    }
  </style>
  <script>
    layui.use('useradmin', layui.factory('useradmin')).use(['admin', 'useradmin', 'table'], function () {
      var $ = layui.$
        , admin = layui.admin
        , view = layui.view
        , setter = layui.setter
        , table = layui.table
        , form = layui.form;

      form.render(null, 'layadmin-userfront-formlist');
      //监听搜索
      form.on('submit(LAY-user-front-search)', function (data) {
        var field = data.field;
        //执行重载
        table.reload('table-instance', {
          where: field
        });
      });

      //事件
      var active = {};
      table.render({
        elem: "#table-instance",
        url: setter.request.baseUrl + "evaluate/list",
        method: "get",
        headers: { token: layui.data("layuiAdmin").token },
        response: {
          statusName: "code",
          statusCode: 0,
          msgName: "msg",
          countName: "totalCount",
          dataName: "evaluate",
        },
        cols: [
          [
            { field: "id", title: "评价id", sort: "true" },
            {
              field: "user", title: "预约用户信息", templet: function (d) {
                return "用户ID:" + d.userId + '</br>' + "用户名:" + d.nickName + '</br>'
              }
            },
            {
              field: "product", title: "产品信息", templet: function (d) {
                return "产品ID:" + d.productId + '</br>' + "产品名:" + d.productName + '</br>'
              }
            },
            { field: "content", title: "评价内容" },
            {
              field: "image", title: "评价图片", templet: "#Image"
            },
            {
              field: "point", title: "评分", templet: function (d) {
                return "游玩体验:" + d.gamePoint + '</br>' + "性价比:" + d.productPoint + '</br>' + "服务态度:" + d.servicePoint + '</br>'
              }
            },
            { field: "comment", title: "评论内容" },
            { field: "createdate", title: "评价时间" },
            { fixed: "right", title: "操作", toolbar: "#table-useradmin-admin" },
          ],
        ],
        page: true,

      });
      table.on("tool(table-instance)", function (obj) {
        var data = obj.data;
        if (obj.event === "del") {
          layer.confirm("真的删除么", function (index) {
            delevaluateHandle({
              id: data.id,
            });
            obj.del();
            layer.close(index);
          })
        } else {
          admin.popup({
            title: "回复评价",
            area: ["500px", "500px"],
            success: function (layero, index) {
              view(this.id)
                .render("evaluate/form", data)
                .done(function () {
                  let _data = data;
                  form.render(null, "layuiadmin-form-admin");
                  form.on('submit(LAY-user-back-submit)', function (data) {
                    var field = data.field;

                    editmessageHandle(Object.assign(_data, field));
                    layui.table.reload('LAY-user-back-manage'); //重载表格
                    layer.close(index);
                  });
                });
            },
          });
        }
      });

      //删除
      function delevaluateHandle(params) {
        admin.req({
          url: setter.request.baseUrl + "evaluate/delete",
          data: {
            ...params,
          },
          type: "get",
          done: function (res) {
            layer.msg(res.msg);
          },
        });
      }

      //修改编辑
      function editmessageHandle(params) {
        admin.req({
          url: setter.request.baseUrl + "evaluate/save",
          data: JSON.stringify(params),
          type: "post",
          dataType: "json"
          , contentType: "application/json",
          done: function (res) {
            layui.table.reload("table-instance");
          },
        });
      }

      // 查看审核图片
      $(document).on("click", ".table-check-img", function (e) {
        var json = {
          title: "审核图片",
          id: 0,
          start: 0,
          data: [
            {
              alt: "",
              pid: 1,
              src: $(e.target).data("img"), //原图地址
              thumb: "",
            },
          ],
        };
        if (json.data[0].src == null || json.data[0].src == "") {
          layer.msg("暂无图片", {
            offset: "15px",
            icon: "2",
            time: 1000
          })
        } else {
          var result = json.data[0].src.split(",");
          var j = new Array;
          for (var i = 0; i < result.length; i++) {
            let json = {
              "src": result[i]
            }
            j[i] = json;
          }
          layer.photos({
            photos: { "data": j },
            anim: 1,
          });
        }
      });

      $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
      });
    });
  </script>
  <script type="text/html" id="Image">
    <button type="button" class="layui-btn layui-btn-xs table-check-img" data-img="{{d.image}}">查看图片</button>
  </script>